from tortoise import fields
from datetime import datetime
from .base import BaseModel, TimestampMixin


class SysOperLog(BaseModel, TimestampMixin):
    """操作日志记录"""

    oper_id = fields.IntField(pk=True, description="日志主键")

    title = fields.CharField(max_length=50, null=True, description="模块标题")

    business_type = fields.IntField(null=True, description="业务类型（0其它 1新增 2修改 3删除）")

    method = fields.CharField(max_length=200, null=True, description="方法名称")

    request_method = fields.CharField(max_length=10, null=True, description="请求方式")

    operator_type = fields.IntField(null=True, description="操作类别（0其它 1后台用户 2手机端用户）")

    oper_name = fields.CharField(max_length=50, null=True, description="操作人员")

    dept_name = fields.CharField(max_length=50, null=True, description="部门名称")

    oper_url = fields.CharField(max_length=255, null=True, description="请求URL")

    oper_ip = fields.CharField(max_length=128, null=True, description="主机地址")

    oper_location = fields.CharField(max_length=255, null=True, description="操作地点")

    oper_param = fields.CharField(max_length=2000, null=True, description="请求参数")

    json_result = fields.CharField(max_length=2000, null=True, description="返回参数")

    oper_status = fields.IntField(null=True, description="操作状态（0正常 1异常）")

    status = fields.CharField(max_length=1, null=True, description="状态（0正常 2删除）")

    error_msg = fields.CharField(max_length=2000, null=True, description="错误消息")

    oper_time = fields.DatetimeField(null=True, description="操作时间")

    cost_time = fields.BigIntField(null=True, description="消耗时间")

    create_by = fields.CharField(max_length=64, null=True, description="创建者")

    create_time = fields.DatetimeField(null=True, description="创建时间")

    update_by = fields.CharField(max_length=64, null=True, description="更新者")

    update_time = fields.DatetimeField(null=True, description="更新时间")

    remark = fields.CharField(max_length=500, null=True, description="备注")

    class Meta:
        table = "sys_oper_log"

    def __str__(self):
        return f"{self.oper_id}"